from django.shortcuts import render

# Create your views here.
from rest_framework_bulk import ListBulkCreateUpdateDestroyAPIView
from redis_app.models import WearTag
from utils.pagination_tools import StandardPagination
from redis_app.serializers import WearTagSerializer
from utils.redis_create_key import cache_page
from utils.search_tools import search_decorator


class WearTagAPI(ListBulkCreateUpdateDestroyAPIView):
    """
    GET -> 获取戴标表数据
    POST -> 创建戴标表数据
    """
    serializer_class = WearTagSerializer
    pagination_class = StandardPagination
    queryset = WearTag.objects.filter(is_active=True)

    @cache_page(timeout=60)
    def get_queryset(self):
        search_dict = search_decorator(self.request)
        return self.queryset.filter(**search_dict)
